package com.example.demo.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.demo.entity.Tran;
import org.apache.ibatis.annotations.*;

import java.util.List;

//用于操作用户表,MyBaits会根据Mapper注解，动态实现UserMapper接口（实现类），动态代理技术
//Spring会自动创建UserMapper接口实现类对应的实例
@Mapper
public interface TranMapper extends BaseMapper<Tran> {

    //根据token查询信息   select * from user where username =
    @Select("select * from tran where num = #{num}")
    Tran selectByNumber(String num);

    @Select("<script>"
            +"select * from tran where 1=1"
            +"<if test='num != null'>"
            +"and num= #{num}"
            +"</if>"
            +"</script>")
    @Results({
            @Result(column = "id",property = "id"),
            @Result(column = "num",property = "num"),
            @Result(column = "ship_from",property = "ship_from"),
            @Result(column = "ship_to",property = "ship_to"),
            @Result(column = "type",property = "type"),
            @Result(column = "weight",property = "weight"),
            @Result(column = "des",property = "des"),
            @Result(column = "state",property = "state")
    })
    List<Tran> getList(@Param("num") String num);
}
